package day1.demo4_linkedList;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Test2 {
    static void compare(List list, boolean isHead){
        long start = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            if(isHead){
                list.add(0,i);
            }else {
                list.add(i);
            }
        }
        long end = System.currentTimeMillis();
        String name;
        if(list instanceof ArrayList){
            name = "ArrayList";
        }else {
            name = "LinkedList";
        }
        String position = isHead?"头部":"尾部";
        System.out.println(name+position+"添加用时："+(end-start)+"毫秒");
    }

    public static void main(String[] args) {
        ArrayList arr = new ArrayList();
        LinkedList lk = new LinkedList();
        compare(arr,true);
        compare(lk,true);
        arr.clear();
        lk.clear();
        System.out.println("===============================");
        compare(arr,false);
        compare(lk,false);

    }

}
